package com.ruoyi.project.wx.controller;

import com.ruoyi.common.utils.bootdo.PageUtils;
import com.ruoyi.common.utils.bootdo.Query;
import com.ruoyi.common.utils.bootdo.R;
import com.ruoyi.project.wx.domain.OrderComDO;
import com.ruoyi.project.wx.service.OrderComService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 订单返佣表
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2019-05-22 15:31:35
 */
 
@Controller
@RequestMapping("/wx/orderCom")
public class OrderComController {
	@Autowired
	private OrderComService orderComService;
	
	@GetMapping()
	@RequiresPermissions("wx:orderCom:orderCom")
	String OrderCom(){
	    return "wx/orderCom/orderCom";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("wx:orderCom:orderCom")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<OrderComDO> orderComList = orderComService.list(query);
		int total = orderComService.count(query);
		PageUtils pageUtils = new PageUtils(orderComList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("wx:orderCom:add")
	String add(){
	    return "wx/orderCom/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("wx:orderCom:edit")
	String edit(@PathVariable("id") String id,Model model){
		OrderComDO orderCom = orderComService.get(id);
		model.addAttribute("orderCom", orderCom);
	    return "wx/orderCom/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("wx:orderCom:add")
	public R save(OrderComDO orderCom){
		if(orderComService.save(orderCom)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("wx:orderCom:edit")
	public R update( OrderComDO orderCom){
		orderComService.update(orderCom);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("wx:orderCom:remove")
	public R remove( String id){
		if(orderComService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("wx:orderCom:batchRemove")
	public R remove(@RequestParam("ids[]") String[] ids){
		orderComService.batchRemove(ids);
		return R.ok();
	}
	
}
